/**
 * Created by LiuJie on 2017/10/16.
 */
var theMap =null;
var thePanorama =null;
var traffic;
var monitor_myDis;
function MapUtils(mapId,options) {
    this.mapId = mapId;
    this.mapObj = null;
    this.options = $.extend({
        // xPoint:120.417544,
        // yPoint:36.189805,
        xPoint:116.690666,
        yPoint:39.542099,
        levels:13
    },options);
    this.basePath = "/js/mapPlugins/img/";
    this.panorama = null;
    this.infoWinOpts = {
        lines: 12, // The number of lines to draw
        angle: 0, // The length of each line
        lineWidth: 0.4, // The line thickness
        pointer: {
            length: 0.75, // The radius of the inner circle
            strokeWidth: 0.042, // The rotation offset
            color: '#1D212A' // Fill color
        },
        limitMax: 'false',   // If true, the pointer will not go past the end of the gauge
        colorStart: '#1ABC9C',   // Colors
        colorStop: '#1ABC9C',    // just experiment with them
        strokeColor: '#F0F3F3',   // to see which ones work best for you
        generateGradient: true,
        width : 350,     // 信息窗口宽度
        height: 250,
    };
    this.markerMap = {};
    this.carInfoMap = {};
}
MapUtils.prototype = {
    init:function () {
        var _localCity = null,
            point = null,
            cityName = "北京",//城市默认为北京
            level = 15;
        var _this = this;
        theMap = this.mapObj = new BMap.Map(this.mapId);
        point = new BMap.Point(this.options.xPoint, this.options.yPoint);
        this.mapObj.centerAndZoom(point, this.options.levels ? this.options.levels : level);
        //this.mapObj.setCurrentCity("北京");
        this.mapObj.addControl(new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT,offset:new BMap.Size(240,$(window).height()-312)}));
        //添加地图类型控件
        this.mapObj.addControl(new BMap.MapTypeControl({
            mapTypes:[
                BMAP_NORMAL_MAP,
                BMAP_HYBRID_MAP
            ]}));
        this.mapObj.enableScrollWheelZoom(true);
        //this.mapObj.addTileLayer(new BMap.PanoramaCoverageLayer());
        var contextMenu = new BMap.ContextMenu();
        var txtMenuItem = [
            {
                text: '放大',
                callback: function () {
                    theMap.zoomIn()
                }
            },
            {
                text: '缩小',
                callback: function () {
                    theMap.zoomOut()
                }
            },
            {
                text: '放置到最大级',
                callback: function () {
                    theMap.setZoom(18)
                }
            },
            {
                text: '查看全国',
                callback: function () {
                    theMap.setZoom(4)
                }
            },
            {
                text: '关闭实景地图',
                callback: function () {
                    //exitqj();
                    theMap.removeTileLayer(traffic);
                    thePanorama.hide();
                }
            },
            {
                text: '在此添加标注',
                callback: function (p) {
                    var marker = new BMap.Marker(p),
                        px = theMap.pointToPixel(p);
                    theMap.addOverlay(marker);
                }
            }
        ];
        for (var i = 0; i < txtMenuItem.length; i++) {
            contextMenu.addItem(new BMap.MenuItem(txtMenuItem[i].text, txtMenuItem[i].callback, 100));
            if (i == 1 || i == 3) {
                contextMenu.addSeparator();
            }
        }
        this.mapObj.addContextMenu(contextMenu);

        thePanorama = this.panorama = new BMap.Panorama(this.mapId);
        this.panorama.setPov({heading: -40, pitch: 6});
        // var stCtrl = new BMap.PanoramaControl(); //构造全景控件
        // stCtrl.setOffset(new BMap.Size(20, 100));
        // this.mapObj.addControl(stCtrl);//添加全景控件



        // var geolocation = new BMap.Geolocation();//获取用户位置定位
        // geolocation.getCurrentPosition(function (result) {
        //     if(this.getStatus() == BMAP_STATUS_SUCCESS){
        //         _this.mapObj.panTo(result.point);
        //     }else{
        //         alert('failed'+this.getStatus());
        //     }
        // },{enableHighAccuracy: true});

        traffic=new BMap.PanoramaCoverageLayer();
        monitor_myDis = new BMapLib.DistanceTool(this.mapObj);

    },
    addMarkIcon:function (carInfo,noPanto) {
        var _this = this;
        var carObj = carInfo;
        var _imgSrc = "";
        var _point = null;
        var carstatus = "在线停止状态";
        //0绿色是跑的，1红色是异常的，2灰色是离线的,3蓝色是停止的，
        //报警类型:1-驶入  2-驶出 3-超速 4-路线偏离 5-停车超时报警  6-疲劳驾驶报警 7-凌晨行车报警
        var carError = 0;
        var accstatus = "熄火";
        var addressDetail = "无详细地址信息!";

        // if (carObj.onlineName == "0") {
        //     carError = 2;
        //     carstatus = "离线状态";
        // } else if (carObj.accFlag == "0") {
        //     carError = 3;
        // } else if (carObj.accFlag == "1") {
        //     carError = 0;
        //     if(parseInt(carObj.speed)<10 || parseInt(carObj.speed)==10 ){
        //         carstatus = "在线停止状态"
        //     }else if(parseInt(carObj.speed)>10){
        //         carstatus = "在线行驶状态"
        //     }
        //     carstatus = "在线";
        // }
        checkedNodeObjs[carObj.id]=true;
        var lineImage = "";
        // onlinetime 2018-04-16 16:29:54
        if (carObj.onlineName == "0") {
            carError = 2;
            carstatus = "离线";
            lineImage = "images/page3/round-black.png";
        }else if (carObj.onlineName == "1" && parseInt(carObj.speed) <10 ) {
            carError = 3;
            carstatus = "停止";
            lineImage = "images/page3/round-blue.png";
        } else if (carObj.onlineName == "1" && parseInt(carObj.speed) >= 10) {
            carError = 0;
            carstatus = "行驶";
            lineImage = "images/page3/round-blue.png";
        }else if(carObj.warningTypes == "3" || carObj.warningTypes == "5" || carObj.warningTypes == "8"){
            carError = 1;
            carstatus = "异常";
            lineImage = "images/page3/round-red.png";
        }
        //DateDiff(carObj.onlinetime,$.formatDate("yyyy-MM-dd HH:mm:ss",new Date()));
        // var $cardom = $("#treeview").find("li[data-baseterminalid='"+carObj.terminal+"']");
        // var $table = $("#carInfoTable");
        // if($cardom && $cardom.length){
        //     $cardom.find("span.isCar").find("img").attr("src",lineImage);
        // }
        // if($table && $table.length){
        //     $table.find("img.carstatus").attr("src",lineImage)
        // }

        // var node = window.carTreeJSON[carObj.terminal];
        // if(node){
        //     carObj["pid"]=node["pid"];
        //     carObj["parentId"]=node["parentId"];
        //     var _onlineName = "-1";
        //     if(node["warningType"] == 0){
        //         _onlineName = "0"
        //     }else if(node["warningType"] == 1 || node["warningType"] == 2){
        //         _onlineName = "1"
        //     }else{
        //         _onlineName = carObj["onlineName"];
        //     }
        //     if(isSelectTreeNode){
        //         if(carObj["onlineName"] != _onlineName){
        //             if(carObj["onlineName"] == "0"){
        //                 TreeApi.refreshTreeNode(carObj,false);
        //             }
        //             if(carObj["onlineName"] == "1"){
        //                 TreeApi.refreshTreeNode(carObj,true);
        //             }
        //         }
        //     }
        // }

        isSelectTreeNode= false;
        //_this.refreshTreeNode(node)
        var _rate=carObj.rate;
        if(carObj.protocolType ==1){
            if (carObj.accFlag == "1") {
                accstatus = "点火";
                _rate = 30+"s"
            }else {
                _rate = 60+"s"
            }
        }else{
            var _rate_ = carObj.rate;
            if(_rate_ == 24 || _rate_ == 1440 || _rate_==null || _rate_==20){
                _rate = 24+"h";
            }else{
                _rate = parseFloat(carObj.rate/60).toFixed(1)+"h";
            }
        }
        var gpsPowerStatus = carObj.gpsPowerStatus;
        var acc = carObj.accFlag;
        var oneHigh = carObj.oneHigh;
        var str=""
        if(gpsPowerStatus == 1){
            str="主电正常, "
        }else{
            str="主电异常, "
        }
        if (acc == 1) {
            str = str+"点火, "
        }else{
            str = str+"熄火, "
        }
        if(oneHigh){
            str=str+" 时长: "+oneHigh+"分钟"
        }else{
            str=str+" 时长: 0 分钟"
        }

        var showCarInfoEvent = this._showCarInfo;
        switch (carInfo.status){
            case "0":
                _imgSrc = "car_online0.fw.png";
                break;
            case "1":
                _imgSrc = "car_online1_0.fw.png";
                break;
            case "2":
                _imgSrc = "car_online2_0.fw.png";
                break;
            case "3":
                _imgSrc = "car_online3_0.fw.png";
                break;
        }
        var _power = carObj.power;
        var powerIcon = "images/power/power_0.png";
        if(_power && !isNaN(_power)){
            powerIcon = _this._queryPowerIcon(_power);
        }else{
            _power = 0;
        }
       // var geocoder = new BMap.Geocoder();
        //geocoder.getLocation(new BMap.Point(carObj.jd, carObj.wd),function (result) {
        if(carObj.addressDetail){
            addressDetail = carObj.addressDetail;
        }
            // var myIcon = new BMap.Icon(_this.basePath + _imgSrc, new BMap.Size(44, 44));
            // var marker = new BMap.Marker(new BMap.Point(carObj.jd, carObj.wd), {icon: myIcon});
            var _theMarker = _this._makeMarker(new BMap.Point(carObj.jd, carObj.wd),carObj.baseCarNo, carObj.driection, carError);
            _this.markerMap[""+carObj.id+""] = _theMarker;
            _this.carInfoMap[""+carObj.id+""] = carObj;
            _this.mapObj.addOverlay(_theMarker);
            if(!noPanto){
                if(isMapPanto){
                    _this.mapObj.panTo(new BMap.Point(carObj.jd, carObj.wd));
                }
            }
            var _carNo = carObj.baseCarNo ? carObj.baseCarNo : "无车牌号";
            var _userName = carObj.userName ? carObj.userName :"无车主姓名";
            _theMarker.removeEventListener("click");
            _theMarker.addEventListener("click",function () {
                var _content ='<div style="border:1px;position: relative">' +
                    (carObj.protocolType == 1 ? '' : '<div style="position: absolute;top:34px;right: 10px;width: 48px;height: 48px;"><img src="'+powerIcon+'" style="position: absolute;top:0;left: 0;width: 48px;height: 48px"><div style="position: absolute;bottom:-14px;display: block;height: 16px;width: 100%;text-align: center"><span>'+_power+'</span>%</div></div>')+
                    '<h4 style="margin:0 0 5px 0;padding:0.2em 0;border-bottom: 2px solid #dd4b39;">车主姓名：' +_userName+ '('+(carObj.protocolType == 1 ? '有线' : '无线')+')</h4>' +
                    '<p style="margin:0;line-height:1.5;font-size:15px;text-indent:2em">' +
                    '车牌号：<span style="font-size:12px;">' +_carNo+ '</span>  </p>'
                    +'<p style="margin:0;line-height:1.5;font-size:15px;text-indent:2em">' +
                    '所属用户：<span style="font-size:12px;">' +carObj.deptName+ '</span>  </p>'
                    +'<p style="margin:0;line-height:1.5;font-size:15px;text-indent:2em">' +
                    '定位时间：<span style="font-size:12px;">' +carObj.gpsDate+ '</span> </p>'
                    +'<p style="margin:0;line-height:1.5;font-size:15px;text-indent:2em">' +
                    '速度：<span style="font-size:12px;">' +carObj.speed+ 'km/h</span> </p>'
                    +'<p style="margin:0;line-height:1.5;font-size:15px;text-indent:2em">' +
                    '总里程：<span style="font-size:12px;">' +carObj.totalDis+ 'km</span> </p>'
                    +'<p style="margin:0;line-height:1.5;font-size:15px;text-indent:2em">' +
                    '状态：<span style="font-size:12px;">' +carstatus+ '</span> </p>'+
                '<p style="margin:0;line-height:1.5;font-size:15px;text-indent:2em">' +
                '回传频率：<span style="font-size:12px;">' +_rate+ '</span> </p>'
                    +'<p style="margin:0;line-height:1.5;font-size:15px;text-indent:2em">' +
                    '位置：<span style="font-size:12px;">' +addressDetail+ '</span> </p>'  +
                    '<div class="row" style="margin-top: 6px;margin-left: 0;margin-right: 0">' +
                    '<div class="col-sm-2" style="padding-right: 0;padding-left: 4px">' +
                    '   <button class="btn  btn-mini btn-primary btn-block m-t" style="padding-left: 0;padding-right: 0;font-size: 12px" onclick="_showCarInfo(0,'+carObj.id+')"><i class="fa fa-edit"></i>车辆</button>' +
                    '</div>' +
                    // '<div class="col-sm-2" style="padding-right: 0;padding-left: 4px">' +
                    // '   <button class="btn btn-mini btn-primary btn-block m-t" style="padding-left: 0;padding-right: 0;font-size: 12px" onclick="_showPanoramaCoverageLayer(\''+carObj.wd+'\',\''+carObj.jd+'\')"><i class="fa fa-map"></i>实景</button>' +
                    // '</div>' +
                    '<div class="col-sm-2" style="padding-right: 0;padding-left: 4px">' +
                    '   <button class="btn btn-mini btn-primary btn-block m-t" style="padding-left: 0;padding-right: 0;font-size: 12px" onclick="_showSportInfo('+carObj.id+',\''+carObj.baseCarNo+'\')"><i class="fa fa-map-marker"></i> 轨迹</button>' +
                    '</div>' +
                    '<div class="col-sm-2" style="padding-right: 0;padding-left: 4px">' +
                    ' <button class="btn btn-primary btn-block m-t" style="padding-left: 0;padding-right: 0;font-size: 12px" onclick="_showCarRoad('+carObj.id+',\''+carObj.jd+'\',\''+carObj.wd+'\')"><i class="fa fa-arrow-down"></i> 追踪</button>' +
                    '</div>' +
                    // '<div class="col-sm-2 loadOrder" style="padding-right: 0;padding-left: 4px">' +
                    // ' <button class="btn btn-primary btn-block m-t" style="padding-left: 0;padding-right: 0;font-size: 12px" onmousedown="orderonMouseDown(event)"> 下发指令</button>' +
                    // '</div>'+
                    '<div class="col-sm-2" style="padding-right: 0;padding-left: 4px">' +
                    ' <button class="btn btn-primary btn-block m-t" style="padding-left: 0;padding-right: 0;font-size: 12px" onclick="chaijiFn('+carObj.id+',\''+carObj.jd+'\',\''+carObj.wd+'\')"> 拆机记录</button>' +
                    '</div>'+
                    '</div>' +
                    '</div>' +
                    "</div>";
                var infoWindow = new BMap.InfoWindow(_content, _this.infoWinOpts);
                _this.mapObj.openInfoWindow(infoWindow,new BMap.Point(carObj.jd, carObj.wd)); //开启信息窗口
            })
        //});


    },
    _makeMarker:function (point, carno, d, flag) {
        if (!d) {
            d = "0";
        }
        var o = new BMap.Marker(point);
        // if (carno) {
            var label = new BMap.Label(carno ? carno :"无车牌号", {offset: new BMap.Size(20, -20)});
            label.setStyle({
                color : "#333",
                fontSize : "14px",
                backgroundColor :"0.05",
                border :"1px solid blue",
                borderColor:"#4B5E8A",
                borderRadius:"5px",
                position:"relative",
                backgroundColor:"#fff"
            });
            o.setLabel(label);
            var angleIcon = this._queryCarIcon(d, flag,carno);
            var myIcon = new BMap.Icon(this.basePath + angleIcon, new BMap.Size(44, 44));
            o.setIcon(myIcon);
        // }
        return o;
    },
    removeMarkers:function (carId) {
        var _marker = this.markerMap[""+carId+""];
        this.mapObj.clearOverlays();
        delete this.markerMap[""+carId+""];
        checkedNodeObjs[carId]=false;
        for(var k in this.markerMap){
            var carObj = this.carInfoMap[k];
            this.addMarkIcon(carObj);
            //0绿色是跑的，1红色是异常的，2灰色是离线的,3蓝色是停止的，
            // var carError = 0;
            // var accstatus = "熄火";
            // var addressDetail = "无详细地址信息!";
            //
            // if (carObj.onlineName == "0") {
            //     carError = 2;
            // } else if (carObj.accFlag == "0") {
            //     carError = 3;
            // } else if (carObj.accFlag == "1") {
            //     carError = 0;
            // }
            // var _theMarker = this._makeMarker(new BMap.Point(carObj.jd, carObj.wd),carObj.baseCarNo, carObj.driection, carError);
            // this.mapObj.addOverlay(_theMarker);
        }
    },
    clearMarkers:function () {
        this.mapObj.clearOverlays();
    },
    _queryPowerIcon:function (powerValue) {
          var _powerValue = parseInt(powerValue);
          var _icon_name = "images/power/power_0.png";
          if(_powerValue > 0 && _powerValue<=5){
              _icon_name = "images/power/power_5.png"
          }else if(_powerValue > 5 && _powerValue<=10){
              _icon_name = "images/power/power_10.png"
          }
          else if(_powerValue > 10 && _powerValue<=15){
              _icon_name = "images/power/power_15.png"
          }else if(_powerValue > 15 && _powerValue<=20){
              _icon_name = "images/power/power_20.png"
          }else if(_powerValue > 20 && _powerValue<=25){
              _icon_name = "images/power/power_25.png"
          }else if(_powerValue > 25 && _powerValue<=30){
              _icon_name = "images/power/power_30.png"
          }else if(_powerValue > 30 && _powerValue<=40){
              _icon_name = "images/power/power_40.png"
          }else if(_powerValue > 40 && _powerValue<=50){
              _icon_name = "images/power/power_50.png"
          }else if(_powerValue > 50 && _powerValue<=60){
              _icon_name = "images/power/power_60.png"
          }else if(_powerValue > 60 && _powerValue<=70){
              _icon_name = "images/power/power_70.png"
          }else if(_powerValue > 70 && _powerValue<=80){
              _icon_name = "images/power/power_80.png"
          }else if(_powerValue > 80 && _powerValue<=90){
              _icon_name = "images/power/power_90.png"
          }else if(_powerValue > 90 && _powerValue<=100){
              _icon_name = "images/power/power_100.png"
          }
          return _icon_name
    },
    /**
     * 0绿色是跑的，1红色是异常的，2灰色是离线的,3蓝色是停止的，
     * @param angles
     * @param flag
     * @returns {string}
     */
    _queryCarIcon:function (angles,flag,carno) {
        var angle=parseInt(angles);
        var icon_name="car_online2_0.fw";
        if(angle==0){
            if(flag==0){
                icon_name="car_online0.fw";
            }else if(flag==1){
                icon_name="car_online1_0.fw";
            }else if(flag==2){
                icon_name="car_online2_0.fw";
            }else if(flag==3){
                icon_name="car_online3_0.fw";
            }

        }else if(angle>0 && angle<45){
            if(flag==0){
                icon_name="car_online0_45.fw";
            }else if(flag==1){
                icon_name="car_online1_0_45.fw";
            }else if(flag==2){
                icon_name="car_online2_0_45.fw";
            }else if(flag==3){
                icon_name="car_online3_0_45.fw";
            }
        }else if(angle==45){
            if(flag==0){
                icon_name="car_online45.fw";
            }else if(flag==1){
                icon_name="car_online1_45.fw";
            }else if(flag==2){
                icon_name="car_online2_45.fw";
            }else if(flag==3){
                icon_name="car_online3_45.fw";
            }
        }else if(angle>45 && angle<90){
            if(flag==0){
                icon_name="car_online45_90.fw";
            }else if(flag==1){
                icon_name="car_online1_45_90.fw";
            }else if(flag==2){
                icon_name="car_online2_45_90.fw";
            }else if(flag==3){
                icon_name="car_online3_45_90.fw";
            }
        }else if(angle==90){
            if(flag==0){
                icon_name="car_online90.fw";
            }else if(flag==1){
                icon_name="car_online1_90.fw";
            }else if(flag==2){
                icon_name="car_online2_90.fw";
            }else if(flag==3){
                icon_name="car_online3_90.fw";
            }
        }else if(angle>90 && angle<135){
            if(flag==0){
                icon_name="car_online90_135.fw";
            }else if(flag==1){
                icon_name="car_online1_90_135.fw";
            }else if(flag==2){
                icon_name="car_online2_90_135.fw";
            }else if(flag==3){
                icon_name="car_online3_90_135.fw";
            }
        }else if(angle==135){
            if(flag==0){
                icon_name="car_online135.fw";
            }else if(flag==1){
                icon_name="car_online1_135.fw";
            }else if(flag==2){
                icon_name="car_online2_135.fw";
            }else if(flag==3){
                icon_name="car_online3_135.fw";
            }
        }else if(angle>135 && angle<180){
            if(flag==0){
                icon_name="car_online135_180.fw";
            }else if(flag==1){
                icon_name="car_online1_135_180.fw";
            }else if(flag==2){
                icon_name="car_online2_135_180.fw";
            }else if(flag==3){
                icon_name="car_online3_135_180.fw";
            }
        }else if(angle==180){
            if(flag==0){
                icon_name="car_online180.fw";
            }else if(flag==1){
                icon_name="car_online1_180.fw";
            }else if(flag==2){
                icon_name="car_online2_180.fw";
            }else if(flag==3){
                icon_name="car_online3_180.fw";
            }
        }else if(angle>180 && angle<225){
            if(flag==0){
                icon_name="car_online180_225.fw";
            }else if(flag==1){
                icon_name="car_online1_180_225.fw";
            }else if(flag==2){
                icon_name="car_online2_180_225.fw";
            }else if(flag==3){
                icon_name="car_online3_180_225.fw";
            }
        }else if(angle==225){
            if(flag==0){
                icon_name="car_online225.fw";
            }else if(flag==1){
                icon_name="car_online1_225.fw";
            }else if(flag==2){
                icon_name="car_online2_225.fw";
            }else if(flag==3){
                icon_name="car_online3_225.fw";
            }
        }else if(angle>225 && angle<270){
            if(flag==0){
                icon_name="car_online225_270.fw";
            }else if(flag==1){
                icon_name="car_online1_225_270.fw";
            }else if(flag==2){
                icon_name="car_online2_225_270.fw";
            }else if(flag==3){
                icon_name="car_online3_225_270.fw";
            }
        }else if(angle==270){
            if(flag==0){
                icon_name="car_online270.fw";
            }else if(flag==1){
                icon_name="car_online1_270.fw";
            }else if(flag==2){
                icon_name="car_online2_270.fw";
            }else if(flag==3){
                icon_name="car_online3_270";
            }
        }else if(angle>270 && angle<315){
            if(flag==0){
                icon_name="car_online270_315.fw";
            }else if(flag==1){
                icon_name="car_online1_270_315.fw";
            }else if(flag==2){
                icon_name="car_online2_270_315.fw";
            }else if(flag==3){
                icon_name="car_online3_270_315.fw";
            }
        }else if(angle==315){
            if(flag==0){
                icon_name="car_online315.fw";
            }else if(flag==1){
                icon_name="car_online1_315.fw";
            }else if(flag==2){
                icon_name="car_online2_315.fw";
            }else if(flag==3){
                icon_name="car_online3_315.fw";
            }
        }else if(angle>315 && angle<350){
            if(flag==0){
                icon_name="car_online315_350.fw";
            }else if(flag==1){
                icon_name="car_online1_315_350.fw";
            }else if(flag==2){
                icon_name="car_online2_315_350.fw";
            }else if(flag==3){
                icon_name="car_online3_315_350.fw";
            }
        }else{
            if(flag==0){
                icon_name="car_online315_350.fw";
            }else if(flag==1){
                icon_name="car_online1_315_350.fw";
            }else if(flag==2){
                icon_name="car_online2_315_350.fw";
            }else if(flag==3){
                icon_name="car_online3_315_350.fw";
            }
        }
        return icon_name+".png"
    }
};

function _showPanoramaCoverageLayer(wd,jd) {
    theMap.addTileLayer(traffic);
    thePanorama.show();
    thePanorama.setPosition(new BMap.Point(jd,wd));
    thePanorama.setOptions({
            navigationControl: false //显示导航控件
    });
};
/**
 * 打开运动轨迹
 * @param id
 * @param carNo
 * @private
 */
function _showSportInfo(id,carNo) {
    window.open("/map/his?carId="+id+"&carNo="+carNo);
};
/**
 * 车辆追踪
 * @param carid
 * @param jd
 * @param wd
 * @private
 */
function _showCarRoad(carid,jd,wd) {
    window.open("/newHis?carId="+carid+"&jd="+jd+"&wd="+wd);
};

(function ($,window,undefined) {
    $.mapMethod = {
        queryDriection:function (angles) {
            var angle=parseInt(angles);
            if(angle==0){
                return "北"
            } else if(angle==90){
                return "东"
            } else if(angle==180){
                return "南"
            } else if(angle==270){
                return "西"
            }else if(angle>0 && angle<90){
                return "东北"
            }else if(angle>90 && angle<180){
                return "东南"
            }else if(angle>180 && angle<270){
                return "西南"
            }else if(angle>270){
                return "西北"
            }
        }
    };

})(jQuery,window,undefined);

//两个日期的差值(d1 - d2).
function DateDiff(d1,d2){
    debugger;
    var day = 24 * 60 * 60 *1000;
    try{
        var dateArr = d1.split("-");
        var checkDate = new Date();
        checkDate.setFullYear(dateArr[0], dateArr[1]-1, dateArr[2]);
        var checkTime = checkDate.getTime();

        var dateArr2 = d2.split("-");
        var checkDate2 = new Date();
        checkDate2.setFullYear(dateArr2[0], dateArr2[1]-1, dateArr2[2]);
        var checkTime2 = checkDate2.getTime();

        var cha = (checkTime - checkTime2)/day;
        return cha;
    }catch(e){
        return false;
    }
}
